﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HF.Framework.SqlDataContract;
using HF.Framework.DataClientDBAgent;

namespace HF.Framework.Log
{
    public class Log
    {
        /// <summary>
        /// 根据DebugHF开关记录错误日志，日志存入ErrorLogs表
        /// </summary>
        /// <param name="errorStr">日志内容</param>
        /// <param name="errorType">日志类型</param>
        public static void WriteErrorLog(string errorStr, string errorType)
        {
            string isDebugHF = System.Configuration.ConfigurationSettings.AppSettings["DebugHF"];
            if (isDebugHF == "true")
            {
                string sqlStr = "insert into ErrorLogs(ErrorStr,ErrorType)values(@ErrorStr,@ErrorType)";
                SqlDataItem sqlItem = new SqlDataItem();
                sqlItem.AppendParameter("@ErrorStr", errorStr);
                sqlItem.AppendParameter("@ErrorType", errorType);
                sqlItem.CommandText = sqlStr;
                ClientDBAgent agent = new ClientDBAgent();
                agent.ExecuteNonQuery(sqlItem);
            }
        }
        /// <summary>
        ///  根据DebugHF开关记服务日志，日志存入ServiceMessageTemp表
        /// </summary>
        /// <param name="Content">日志内容</param>
        /// <param name="msgtype">日志类型</param>
        public static void WriteServiceLog(string Content, string msgtype)
        {
            string isDebugHF = System.Configuration.ConfigurationSettings.AppSettings["DebugHF"];
            if (isDebugHF == "true")
            {
                string sqlStr = "insert into ServiceMessageTemp(Content,msgtype)values(@Content,@msgtype)";
                SqlDataItem sqlItem = new SqlDataItem();
                sqlItem.AppendParameter("@Content", Content);
                sqlItem.AppendParameter("@msgtype", msgtype);

                sqlItem.CommandText = sqlStr;
                ClientDBAgent agent = new ClientDBAgent();
                agent.ExecuteNonQuery(sqlItem);
            }
        }
        /// <summary>
        /// 定时读取日志信息的功能。
        /// 设置服务日志状态为以显示过，以显示过的日志不需要再显示。
        /// </summary>
        /// <param name="guid"></param>
        public static void SetSeviceLogShowed(string guid)
        {
            string sqlStr = "update ServiceMessageTemp set isShowed='1' where guid=@guid";
            SqlDataItem sqlItem = new SqlDataItem();
            sqlItem.AppendParameter("@guid", guid);
            sqlItem.CommandText = sqlStr;
            ClientDBAgent agent = new ClientDBAgent();
            agent.ExecuteNonQuery(sqlItem);
        }
    }
}
